//
//  GeneralManagerViewController.m
//  Wallets Manager
//
//  Created by Tung Nguyen on 9/26/12.
//  Copyright (c) 2012 BKHN. All rights reserved.
//

#import "GeneralManagerViewController.h"

@interface GeneralManagerViewController ()
{
    CustomAlertView *alertView;
}
@end

@implementation GeneralManagerViewController
@synthesize scrollView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.tabBarItem.image = [UIImage imageNamed:@"money-01.png"];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrollView.contentSize = CGSizeMake(640, 80);
    scrollView.delegate = self;
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(scrollViewPageChanged) userInfo:nil repeats:YES];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [self setScrollView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - IBAction Delegate
- (IBAction)backButtonPressed:(id)sender {
   folyAppDelegate *myDelegate =   (folyAppDelegate *)[[UIApplication sharedApplication]delegate];
    [myDelegate.navigationController popViewControllerAnimated:YES];
    
}

- (IBAction)addButtonPressed:(id)sender {
//    AddIncomeViewController *addIncomeViewController = [[AddIncomeViewController alloc]init];
//    [self.navigationController pushViewController:addIncomeViewController animated:YES];
    
//    NSArray* customArray = [[NSBundle mainBundle] loadNibNamed:@"CustomAlertView"
//                                                        owner:self
//                                                      options:nil];
//    
//    CustomAlertView *alertView = [customArray objectAtIndex:0];
//    [self.view addSubview:alertView];
    alertView = [[CustomAlertView alloc]initWithNibName:@"CustomAlertView" bundle:nil];
    
    [self.view addSubview:alertView.view];
    NSLog(@"%@", [self.view subviews]);
}

#pragma mark - ScrollView Delegate
- (void) scrollViewPageChanged {
    
    CGRect currentFrame = scrollView.frame;
    if(currentFrameIndex == 0) {
        currentFrameIndex = 1;
        currentFrame.origin.x = 320;
        currentFrame.origin.y = 0;
    } else {
        currentFrameIndex = 0;
        currentFrame.origin.x = 0;
        currentFrame.origin.y = 0;
    }
    
    [scrollView scrollRectToVisible:currentFrame animated:YES] ;
}
@end
